<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">

<head>
    <title>公告管理</title>
    <link href="/js/bstable/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="/js/bstable/css/bootstrap-table.css" rel="stylesheet" type="text/css">
    <link href="/css/table.css" rel="stylesheet" type="text/css">

    <script src="/js/vue.js"></script>
    <script src="/js/axios.min.js"></script>
</head>
<body style="background-color: #ecf0f5;font-family: 微软雅黑;color: #475059;min-width: 1000px;overflow: auto">
<div id="app" >
    <div class="notice_main">
        <table id="table" class="table_style" style="margin: 0 auto" > </table>
    </div>
    <script src="js/jquery/jQuery-2.2.0.min.js"></script>
    <script src="js/bstable/js/bootstrap.min.js"></script>
    <script src="js/bstable/js/bootstrap-table.js"></script>
    <script src="js/bstable/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="js/layer_v2.1/layer/layer.js"></script>
    <div class="alert alert-danger" role="alert">
        <p>修改广告位信息</p>
    </div>
    <form method="post" enctype="multipart/form-data"  class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-2 control-label">位置</label>
            <div class="col-sm-8">
                <input type="text" v-model="ad.location" name="comtent"  class="form-control" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">广告标题</label>
            <div class="col-sm-8">
                <input type="text" v-model="ad.title" name="title"  class="form-control" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">图片</label>
            <div class="col-sm-8">
                <input type="text" v-model="ad.picture" name="comtent"  class="form-control" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">链接</label>
            <div class="col-sm-8">
                <input type="text" v-model="ad.link" name="comtent"  class="form-control" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">操作人</label>
            <div class="col-sm-8">
                <select v-model= "ad.admin_id" class="form-control" name="admin_id">
                    <option v-for="admin in admininfo" v-bind:value="admin.admin_id" >
                        {{admin.admin_name}}
                    </option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">操作时间</label>
            <div class="col-sm-8">
                <input type="date" v-model="ad.posted" name="release_time" class="form-control" >
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button"  @click="updateAd" class="btn btn-info">保存修改</button>
            </div>
        </div>
    </form>
</div>
</body>
</html>

<script>
    new Vue({
        el:"#app",
        data:{
            admininfo:[],
            ad:{
            }
        },
        methods:{
            updateAd:function(){
                console.log(this.ad)
                axios.post('/ad/update', this.ad)
                    .then(function (response) {
                        console.log(response.data);
                        if(response.data==1){
                            alert("修改成功！")
                            location.href="adv.html"
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            }
        },
        mounted(){
            var _this = this
            var ad_id = window.localStorage.getItem("sid")
            console.log("主键为："+ ad_id)
            axios.get('/ad/update',{
                params:{
                    ad_id: ad_id
                }
            })
                .then(function (response){
                    _this.ad = response.data
                    console.log(response.data);
                })
                .catch(function (error){
                    console.log(error);
                });
            //this.$forceUpdate()

            _this = this
            axios.get('/admin/list')
                .then(function (response){
                    _this.admininfo = response.data
                    console.log(_this.admininfo);
                })
                .catch(function (error){
                    console.log(error);
                });
        },
    })
</script>